A character class is a number of characters enclosed in square brackets. For example,
[0123456789]
matches any one of the characters inside the brackets. This character class matches any single digit. This digit character class can be written more simply as:
[0-9]
The '-' indicates a range of characters between the '0' and '9'. The order in which a range of characters is specified is related to the order in which characters appear in the ASCII character set. A complete list of the 7-bit ASCII characters can be found in Appendix A.
Another example of a range within a character class is,
[a-z]
this would match any lower case character, while
[a-zA-Z]
would match any uppercase or lowercase character.
If the first character after the '[' is a circumflex ( ^ ), the character class matches all characters which are not listed in the brackets. For example,
[^0-9]
would match all characters that are not digits.
Note |
A '-' or ']' as the first character after the '[' is interpreted literally to allow the user to include dashes and square brackets in character classes. |
See Also